using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PickGun : MonoBehaviour
{
    public int Num;
    private Collider2D coll;
    private Collider2D playerColl;
    public LayerMask playerLayer;
    public GameObject imformation;
    void Start()
    {
        imformation.SetActive(false);
        coll = GetComponent<Collider2D>();
    }
    void Update()
    {
        if (coll.IsTouchingLayers(playerLayer))
        {
            imformation.SetActive(true);
            //imformation.transform.localScale = new Vector3(1, 1, 1);
            if (Input.GetKeyDown(KeyCode.E))
            {
                if (Num >= 0)
                {
                    playerColl.GetComponent<PlayerCon>().PickGun(Num);
                }
                else if (Num == -1)
                {
                    playerColl.GetComponent<PlayerCon>().parameterPlayer.NowHP += 2;
                }
                else if (Num == -2)
                {
                    playerColl.GetComponent<PlayerCon>().parameterPlayer.NowMP += 80;
                }
                else if (Num == -3)
                {
                    playerColl.GetComponent<PlayerCon>().parameterPlayer.NowHP += Random.Range(1, 5);
                }
                if (Num >= -2)
                {
                    Destroy(gameObject);
                }
                else
                {
                    coll.enabled = false;
                }
            }
        }
        else
        {
            imformation.SetActive(false);
        }
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.layer == LayerMask.NameToLayer("Player"))
        {
            playerColl = collision;
        }
    }
}
